package com.huamao.niceman.scrollviewpager.base;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

/**
 * Created by LuanXianSheng on 2017/2/27.
 */

public abstract  class BasePresent<T> {
    //View接口类型弱引用
    public Reference<T> mViewFre ;

    /**
     * 与View进行关联
     * @param view
     */
    public void attachView(T view){
        //建立关联
        mViewFre = new WeakReference<T>(view) ;
    }
    /**
     *  获取view
     */
    public T getView(){
        return mViewFre.get() ;
    }

    /**
     * 判断是否与View进行了关联
     * @return
     */
    public boolean isViewAttached(){
        return mViewFre != null && mViewFre.get() != null ;
    }

    /**
     * 与view进行进行接触关联
     */
    public  void detachView(){
        if (mViewFre != null){
            mViewFre.clear();
            mViewFre = null ;
        }
    }
}
